import 'package:flutter/material.dart';
import 'package:library_base/base/base_app_state_page.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/goods_child_entity.dart';
import 'package:library_base/entities/shipper_entity.dart';
import 'package:library_base/entities/suppliers_shops_list_entity.dart';
import 'package:library_base/ext/bool_ext.dart';
import 'package:library_base/ext/double_ext.dart';
import 'package:library_base/ext/list_ext.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:get/get.dart';
import 'package:library_base/net/apis.dart';
import 'package:library_base/network/http_config.dart';
import 'package:library_base/res/edge.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/geometry.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/res/widget_generator.dart';
import 'package:library_base/route/routers.dart';
import 'package:library_base/utils/get_util.dart';
import 'package:library_base/utils/num_util.dart';
import 'package:library_base/utils/sp_util.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:library_base/utils/widget_generate_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/button/ink_bg_well.dart';
import 'package:library_base/widget/dash_painter/dotted_border.dart';
import 'package:library_base/entities/generated/json/goods_child_entity.g.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:module_administrator/page/create_purchase_order/create_purchase_order_controller.dart';
import 'package:library_base/entities/suppliers_entity.dart';
import 'package:library_base/entities/warehouse_entity.dart';
import 'package:library_base/widget/dialog/dialog_util.dart';

class CreatePurchaseOrderPage extends StatefulWidget {
  const CreatePurchaseOrderPage({Key? key}) : super(key: key);

  @override
  _CreatePurchaseOrderPageState createState() => _CreatePurchaseOrderPageState();
}

class _CreatePurchaseOrderPageState
    extends BaseState<CreatePurchaseOrderPage, CreatePurchaseOrderController> {
  bool isEdit = false;

  @override
  CreatePurchaseOrderController registerController() => Get.find<CreatePurchaseOrderController>();

  @override
  void onCreate() {
    isEdit = Get.arguments!=null;
    setTitle(isEdit?MultiLanguage.editPurchaseOrder.tr:MultiLanguage.createPurchaseOrder.tr);
    setTitleSize(32.sp);
  }

  @override
  List<Widget> getMainChildrenWidget(BuildContext context) {
    return [
      baseGetxController!.listDataSelected.value.isEmpty?
      Container(
        padding: edgeLR24,
        color: ThemeUtil.getTheme().colorScheme.secondary,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: _list(),
        ),
      ):Container(),
      Expanded(child: GetBuilder<CreatePurchaseOrderController>(builder: (logic) {
        return baseGetxController!.listDataSelected.value.isEmpty
            ? Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  LocalImage('admin_empty', package: Constant.packAdmin(), width: 0.6.sw),
                  Text(MultiLanguage.noSuchProduct.tr, style: TextStyles.textSecondary28)
                ],
              )
            : Material(
                color: ThemeUtil.getTheme().secondaryBgColor(),
                child: MediaQuery.removePadding(
                  context: context,
                  removeTop: true,
                  removeBottom: true,
                  child: ListView(
                    children: _buildGoodItems(),
                  ),
                ),
              );
      })),
      Container(
        padding: GenerateWidgetUtil.buttonGap(),
        child: Row(
          children: [
            Expanded(
              child: GradientButton(
                ThemeUtil.getTheme(),
                radius: const BorderRadius.only(
                    topLeft: Radius.circular(50), bottomLeft: Radius.circular(50)),
                colors: ThemeUtil.getTheme().buttonLeftBgColor(),
                height: 80.w,
                text: MultiLanguage.cancel.tr,
                onPressed: () {
                  Get.back();
                },
              ),
            ),
            Expanded(
              child: GradientButton(
                ThemeUtil.getTheme(),
                radius: const BorderRadius.only(
                    topRight: Radius.circular(50), bottomRight: Radius.circular(50)),
                height: 80.w,
                text: MultiLanguage.save.tr,
                onPressed: () {
                  if (!baseGetxController!.isCanShowBottomOption()) {
                    return;
                  }
                  //假如没有提交草稿的功能直接保存
                  if(!baseGetxController!.isShowSubmitDraft){
                    if(baseGetxController!.isShowGenerateSalesOrderDialog){
                      baseGetxController!.requestUniversal<SuppliersShopsListEntity>(Apis.SUPPLIERS_SHOPS_LIST,
                          method: FBResultFul.GET,
                          queryParameters: {
                            "supplierId":baseGetxController!.supplier.value!.id,
                          },
                          resultSuccessListCall: (data) async {
                            if(data.isEmpty){
                              baseGetxController!.saveAndSubmit.call(isEmpty : true);
                            }else{
                              GetHelper.back();
                              var map = <String,dynamic>{};
                              map["SuppliersShopsListEntities"] = data;
                              map["CallBack"] = _callBackSuppliersShopsListEntity;
                              map["suppliersShopsListEntity"] = baseGetxController!.shop;
                              DialogUtil.showGenerateSalesOrderDialog(arguments: map);
                            }
                          });
                    }else{
                      baseGetxController!.saveAndSubmit.call();
                    }
                  }else{
                    Map<String, dynamic> arguments = {};
                    arguments['CallBack'] = _option;
                    DialogUtil.showBottomOptionDialog(arguments: arguments);
                  }
                },
              ),
            ),
          ],
        ),
      )
    ];
  }

  _callBackSuppliersShopsListEntity(SuppliersShopsListEntity? suppliersShopsListEntity){
    baseGetxController!.suppliersShopsListEntity = suppliersShopsListEntity;
    baseGetxController!.saveAndSubmit.call();
  }

  _option(String action) {
    if (action == MultiLanguage.saveAndSubmit.tr) {
      if(baseGetxController!.isShowGenerateSalesOrderDialog){
        baseGetxController!.requestUniversal<SuppliersShopsListEntity>(Apis.SUPPLIERS_SHOPS_LIST,
            method: FBResultFul.GET,
            queryParameters: {
              "supplierId":baseGetxController!.supplier.value!.id,
            },
            resultSuccessListCall: (data) async {
              if(data.isEmpty){
                baseGetxController!.saveAndSubmit.call(isEmpty : true);
              }else{
                GetHelper.back();
                var map = <String,dynamic>{};
                map["SuppliersShopsListEntities"] = data;
                map["CallBack"] = _callBackSuppliersShopsListEntity;
                map["suppliersShopsListEntity"] = baseGetxController!.shop;
                DialogUtil.showGenerateSalesOrderDialog(arguments: map);
              }
            });
      }else{
        baseGetxController!.saveAndSubmit.call();
      }
    } else if (action == MultiLanguage.saveDraft.tr) {
      baseGetxController!.saveDraft.call();
    }
  }

  List<Widget> _list() {
    List<Widget> widgets = <Widget>[];

    Widget purchase = Row(children: [
      Expanded(
          flex: 2,
          child: Text(MultiLanguage.purchaseOrderNo.tr,
              style: TextStyles.textNormal28, textAlign: TextAlign.end)),
      gapW24,
      Expanded(
          flex: 6,
          child: GetBuilder<CreatePurchaseOrderController>(builder: (logic) {
            return Text(logic.purchaseOrderNo.value, style: TextStyles.textNormal28);
          })),
    ]);
    Widget supplier = Row(children: [
      Expanded(
          flex: 2,
          child:
              Text(MultiLanguage.supplier.tr, style: TextStyles.textNormal28, textAlign: TextAlign.end)),
      gapW24,
      Expanded(
          flex: 6,
          child: GetBuilder<CreatePurchaseOrderController>(builder: (logic) {
            return GestureDetector(
              onTap: () {
                baseGetxController?.requestUniversal<SuppliersEntity>(Apis.SUPPLIERS,
                    method: FBResultFul.GET, queryParameters: {"supplierType": 'GOODS'},
                    resultSuccessListCall: (list) async {
                  var callbackSuppliersEntity = await Get.toNamed(Routers.chooseSupplierPage,
                      arguments: {'Supplier': list, 'SelectedSupplier': logic.supplier.value});
                  if (callbackSuppliersEntity != null &&
                      logic.supplier.value != callbackSuppliersEntity) {
                    logic.supplier.value = callbackSuppliersEntity;
                    logic.update();
                  }
                });
              },
              child: Container(
                  padding: GenerateWidgetUtil.optionSetUpGap1(),
                  decoration: BoxDecoration(
                      borderRadius: const BorderRadius.all(Radius.circular(30.0)),
                      border:
                          Border.all(color: ThemeUtil.getTheme().secondaryTextColor(), width: 1.0)),
                  child: Row(children: [
                    Expanded(
                        child: Text(
                            logic.supplier.value == null
                                ? MultiLanguage.pleaseSelectSupplier.tr
                                : logic.supplier.value!.name,
                            style: logic.supplier.value == null
                                ? TextStyles.textSecondary28
                                : TextStyles.textNormal28)),
                    LocalImage('admin_grey_rightward_arrow',
                        package: Constant.packAdmin(), width: 20.w, height: 20.w),
                  ])),
            );
          }))
    ]);
    Widget warehouse = Row(children: [
      Expanded(
          flex: 2,
          child: Text(MultiLanguage.warehouse.tr,
              style: TextStyles.textNormal28, textAlign: TextAlign.end)),
      gapW24,
      Expanded(
          flex: 6,
          child: GetBuilder<CreatePurchaseOrderController>(
            builder: (logic) {
              return GestureDetector(
                onTap: () {
                  baseGetxController?.requestUniversal<WarehouseEntity>(Apis.WAREHOUSE,
                      method: FBResultFul.GET, resultSuccessListCall: (list) async {
                    var callbackSuppliersEntity = await Get.toNamed(Routers.chooseWarehousePage,
                        arguments: {'Warehouse': list, 'SelectedWarehouse': logic.warehouse.value});
                    if (callbackSuppliersEntity != null &&
                        logic.warehouse.value != callbackSuppliersEntity) {
                      logic.warehouse.value = callbackSuppliersEntity;
                      logic.update();
                    }
                  });
                },
                child: Container(
                    padding: GenerateWidgetUtil.optionSetUpGap1(),
                    decoration: BoxDecoration(
                        borderRadius: const BorderRadius.all(Radius.circular(30.0)),
                        border: Border.all(
                            color: ThemeUtil.getTheme().secondaryTextColor(), width: 1.0)),
                    child: Row(children: [
                      Expanded(
                          child: Text(
                              logic.warehouse.value == null
                                  ? MultiLanguage.pleaseSelectReceivingWarehouse.tr
                                  : logic.warehouse.value!.whName,
                              style: logic.warehouse.value == null
                                  ? TextStyles.textSecondary28
                                  : TextStyles.textNormal28)),
                      LocalImage('admin_grey_rightward_arrow',
                          package: Constant.packAdmin(), width: 20.w, height: 20.w),
                    ])),
              );
            },
          )),
    ]);
    Widget consignor = Row(children: [
      Expanded(
          flex: 2,
          child: Text(MultiLanguage.consignor.tr,
              style: TextStyles.textNormal28, textAlign: TextAlign.end)),
      gapW24,
      Expanded(
          flex: 6,
          child: GetBuilder<CreatePurchaseOrderController>(
            builder: (logic) {
              return GestureDetector(
                onTap: () {
                  baseGetxController?.requestUniversal<ShipperEntity>(Apis.SHIPPER,
                      method: FBResultFul.GET, resultSuccessListCall: (list) async {
                    var callbackSuppliersEntity = await Get.toNamed(Routers.chooseShipperPage,
                        arguments: {'Shipper': list, 'SelectedShipper': logic.consignor.value});
                    if (callbackSuppliersEntity != null &&
                        logic.consignor.value != callbackSuppliersEntity) {
                      logic.consignor.value = callbackSuppliersEntity;
                      logic.listDataSelected.value.clear();
                      logic.update();
                    }
                  });
                },
                child: Container(
                    padding: GenerateWidgetUtil.optionSetUpGap1(),
                    decoration: BoxDecoration(
                        borderRadius: const BorderRadius.all(Radius.circular(30.0)),
                        border: Border.all(
                            color: ThemeUtil.getTheme().secondaryTextColor(), width: 1.0)),
                    child: Row(children: [
                      Expanded(
                          child: Text(
                              logic.consignor.value == null
                                  ? MultiLanguage.pleaseSelectConsignor.tr
                                  : logic.consignor.value!.shipperName,
                              style: logic.consignor.value == null
                                  ? TextStyles.textSecondary28
                                  : TextStyles.textNormal28)),
                      LocalImage('admin_grey_rightward_arrow',
                          package: Constant.packAdmin(), width: 20.w, height: 20.w),
                    ])),
              );
            },
          ))
    ]);
    // Widget generateSalesOrder = Row(children: [
    //   Expanded(
    //       flex: 2,
    //       child: Text(Messages.generateSalesOrder.tr,
    //           style: TextStyles.textNormal28, textAlign: TextAlign.end)),
    //   gapW24,
    //   Expanded(
    //       flex: 6,
    //       child: GetBuilder<CreatePurchaseOrderController>(
    //         builder: (logic) {
    //           return GestureDetector(
    //             onTap: baseGetxController!.generateSalesOrder,
    //             child: Container(
    //                 padding: GenerateWidgetUtil.optionSetUpGap1(),
    //                 decoration: BoxDecoration(
    //                     borderRadius: const BorderRadius.all(Radius.circular(30.0)),
    //                     border: Border.all(
    //                         color: ThemeUtil.getTheme().secondaryTextColor(), width: 1.0)),
    //                 child: Row(children: [
    //                   Expanded(
    //                       child: Text(
    //                           logic.consignor.value == null
    //                               ? Messages.pleaseSelectConsignor.tr
    //                               : logic.consignor.value!.shipperName,
    //                           style: logic.consignor.value == null
    //                               ? TextStyles.textSecondary28
    //                               : TextStyles.textNormal28)),
    //                   LocalImage('admin_grey_rightward_arrow',
    //                       package: Constant.packAdmin(), width: 20.w, height: 20.w),
    //                 ])),
    //           );
    //         },
    //       ))
    // ]);
    Widget remark = Row(children: [
      Expanded(
          flex: 2,
          child: Text(MultiLanguage.remark.tr,
              style: TextStyles.textNormal28, textAlign: TextAlign.end)),
      gapW24,
      Expanded(
          flex: 6,
          child: inputInfo(
              keyboardType: TextInputType.text,
              controller: baseGetxController!.remarkTextEditingController,
              focusNode: baseGetxController!.remarkFocusNode,
              decoration: BoxDecoration(
                  borderRadius: const BorderRadius.all(Radius.circular(30.0)),
                  border: Border.all(
                      color: ThemeUtil.getTheme().secondaryTextColor(),
                      width: 1.0)),
              borderRadius: geometry30,
              hintText: MultiLanguage.pleaseEnterComments.tr))
    ]);
    Widget countAndAmount = Row(children: [
      Stack(
        children: [
          LocalImage('admin_count_bg', package: Constant.packAdmin(), width: 343.w, height: 124.w),
          Positioned(
            left: 24.w,
            top: 24.w,
            child: Text(MultiLanguage.commodityQuantity.tr, style: TextStyles.textBlack30),
          ),
          Positioned(
            left: 24.w,
            top: 75.w,
            child: GetBuilder<CreatePurchaseOrderController>(builder: (logic) {
              return Text('${logic.numberOfProducts}', style: TextStyles.textFifthColor28);
            }),
          )
        ],
      ),
      Gaps.hGap16,
      Stack(
        children: [
          LocalImage('admin_amount', package: Constant.packAdmin(), width: 343.w, height: 124.w),
          Positioned(
            left: 24.w,
            top: 24.w,
            child: Text(MultiLanguage.purchaseOrderAmount.tr, style: TextStyles.textBlack30),
          ),
          Positioned(
            left: 24.w,
            top: 75.w,
            child: GetBuilder<CreatePurchaseOrderController>(builder: (logic) {
              return Text('¥ ${NumUtil.formatNum(logic.purchaseOrderAmount.value)}',
                  style: TextStyles.textFourthColor28);
            }),
          )
        ],
      ),
    ]);

    Widget addGoods = GestureDetector(
        onTap: _addGoods,
        child: DottedBorder(
          color: ThemeUtil.getTheme().secondaryTextColor(),
          dashPattern: const [4, 2],
          strokeWidth: 1,
          borderType: BorderType.RRect,
          radius: const Radius.circular(5),
          child: Container(
            alignment: Alignment.center,
            padding: GenerateWidgetUtil.vw25Gap(),
            child: Row(mainAxisSize: MainAxisSize.min, children: [
              LocalImage('admin_add',
                  package: Constant.packAdmin(), width: 25.w, height: 25.w),
              Gaps.hGap16,
              Text(MultiLanguage.addItem.tr, style: TextStyles.textSecondary28)
            ]),
          ),
        ));
    widgets.add(gapH24);
    widgets.add(purchase);
    widgets.add(gapH24);
    widgets.add(supplier);
    widgets.add(gapH24);
    widgets.add(warehouse);
    widgets.add(gapH24);
    widgets.add(consignor);
    // widgets.add(gapH24);
    // widgets.add(generateSalesOrder);
    widgets.add(gapH24);
    widgets.add(remark);
    widgets.add(gapH24);
    widgets.add(countAndAmount);

    if (!isEdit) {
      widgets.add(gapH24);
      widgets.add(addGoods);
    }

    widgets.add(gapH24);
    return widgets;
  }

  ///添加商品
  _addGoods() async {
    if (baseGetxController!.consignor.value == null) {
      DialogUtil.showCupertinoAlertDialog(context,
          title: MultiLanguage.selectConsignor.tr,
          content: MultiLanguage.pleaseFirstSelectConsignor.tr,
          cancel: MultiLanguage.cancelAdd.tr,
          confirm: MultiLanguage.selectConsignor.tr,
          cancelPressed: () => Get.back(),
          confirmPressed: () async {
            Get.back(result: baseGetxController!.consignor.value);
            baseGetxController?.requestUniversal<ShipperEntity>(Apis.SHIPPER,
                method: FBResultFul.GET, resultSuccessListCall: (list) async {
              var callbackSuppliersEntity =
                  await Get.toNamed(Routers.chooseShipperPage, arguments: {
                'Shipper': list,
                'SelectedShipper': baseGetxController!.consignor.value
              });
              if (callbackSuppliersEntity != null &&
                  baseGetxController!.consignor.value !=
                      callbackSuppliersEntity) {
                baseGetxController!.consignor.value = callbackSuppliersEntity;
                baseGetxController!.update();
              }
            });
          });
    } else {
      var goods = await Get.toNamed(Routers.addGoodsPage, arguments: {
        'GoodsChildEntities': baseGetxController!.listDataSelected.value,
        'shipperId': baseGetxController!.consignor.value!.id,
      });

      if (goods != null) {
        baseGetxController!.listDataSelected.value = goods;
        setSafeState();
      }
    }
  }

  ///构建Item
  List<Widget> _buildGoodItems() {
    var widgets = <Widget>[];

    if(baseGetxController!.listDataSelected.value.isNotEmpty){
      widgets.add(Container(
        padding: edgeLR24,
        color: ThemeUtil.getTheme().colorScheme.secondary,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: _list(),
        ),
      ));
    }

    baseGetxController!.listDataSelected.value.forEachIndexed((index, element) {
      if (baseGetxController!.listDataSelected.value.length == 1) {
        widgets.add(gapH18);
        widgets.add(_buildGoodItem(index, element));
        widgets.add(gapH18);
      } else if (index == (baseGetxController!.listDataSelected.value.length - 1)) {
        widgets.add(gapH18);
        widgets.add(_buildGoodItem(index, element));
        widgets.add(gapH18);
      } else {
        widgets.add(gapH18);
        widgets.add(_buildGoodItem(index, element));
      }
    });
    return widgets;
  }

  Widget _buildGoodItem(int index,GoodsChildEntity goodsChildEntity) {
    var widget = Container(
      margin: edgeLR24,
      decoration: BoxDecoration(
        color: ThemeUtil.getTheme().colorScheme.secondary,
        borderRadius: const BorderRadius.all(Radius.circular(8.0)),
      ),
      child: GestureDetector(
        onTap: () => _showAddGoodsInfoDialog(index,goodsChildEntity),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              color: Colors.transparent,
              child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
                Visibility(
                    visible: false,
                    child: GenerateWidgetUtil.goodItemRoundNetImage(Constant.placeholderImg)),
                gapW24,
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      gapH24,
                      Text(
                        goodsChildEntity.goodsName,
                        style: TextStyles.textBlackBold30,
                      ),
                      Visibility(
                        visible: false,
                        child: Container(
                          padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 8.w),
                          decoration: BoxDecoration(
                            color: ThemeUtil.getTheme().secondaryBgColor(),
                            borderRadius: BorderRadius.circular(3),
                          ),
                          child: Text(
                            '${MultiLanguage.currentInventory.tr}：-',
                            style: TextStyles.textSixthColor24,
                          ),
                        ),
                      ),
                      gapH18,
                      goodsChildEntity.totalCount == null
                          ? Row(
                              children: [
                                Icon(
                                  Icons.error,
                                  size: 28.sp,
                                  color: Colors.red,
                                ),
                                Gaps.wwGap8,
                                Text(
                                  MultiLanguage.noInformationEntered.tr,
                                  style: TextStyles.textEighthColor28,
                                ),
                              ],
                            )
                          : RichText(
                              text: TextSpan(
                                  text: "${MultiLanguage.purchaseQuantity.tr}: ",
                                  style: TextStyles.textSixthColor28,
                                  children: [
                                  TextSpan(
                                      text: "${goodsChildEntity.totalCount ?? ''}",
                                      style: TextStyles.textNormal28)
                                ])),
                    ],
                  ),
                ),
                Visibility(
                  visible: !isEdit,
                  child: deleteBgWell(goodsChildEntity, onTap: (goodsChildEntity) {
                    DialogUtil.showCupertinoAlertDialog(context,
                        title: MultiLanguage.deleteGoods.tr,
                        content: MultiLanguage.isDeleteGoods.tr,
                        cancel: MultiLanguage.cancel.tr,
                        confirm: MultiLanguage.determine.tr,
                        cancelPressed: () => Get.back(),
                        confirmPressed: () async {
                          Get.back();
                          if (baseGetxController!.listDataSelected.value.contains(goodsChildEntity)) {
                            baseGetxController!.listDataSelected.value.remove(goodsChildEntity);
                            baseGetxController!.updateCount();
                            setSafeState();
                          }
                        });
                  }),
                ),
              ]),
            ),
            gapH24,
            Visibility(
              visible: goodsChildEntity.totalCount != null && goodsChildEntity.isExpand,
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    // margin: EdgeInsets.only(left: 174.w),
                    margin: EdgeInsets.only(left: 24.w),
                    alignment: Alignment.centerLeft,
                    child: RichText(
                        text: TextSpan(
                            text: "${MultiLanguage.purchasePrices.tr}: ",
                            style: TextStyles.textSixthColor28,
                            children: [
                          TextSpan(
                              text: '¥ ${goodsChildEntity.price.remoteAsLocalUnit(goodsChildEntity.unit) ?? ""}',
                              style: TextStyles.textNormal28)
                        ])),
                  ),
                  gapH18,
                  Container(
                    // margin: EdgeInsets.only(left: 174.w),
                    margin: EdgeInsets.only(left: 24.w),
                    child: RichText(
                        text: TextSpan(
                            text: "${MultiLanguage.purchaseWeight.tr}: ",
                            style: TextStyles.textSixthColor28,
                            children: [
                          TextSpan(
                              text: '${(goodsChildEntity.totalWeight ?? 0.0).remoteUnitTransitionLocalUnitStr(goodsChildEntity.unit)} ${SPUtil.isJin.unitStrZh()}',
                              style: TextStyles.textNormal28)
                        ])),
                  ),
                  gapH18,
                  Container(
                    margin: EdgeInsets.only(left: 24.w),
                    child: RichText(
                        text: TextSpan(
                            text: "${MultiLanguage.purchaseAmount.tr}: ",
                            style: TextStyles.textSixthColor28,
                            children: [
                          TextSpan(
                              text: '¥ ${goodsChildEntity.purchaseAmount ?? ''}',
                              style: TextStyles.textNormal28)
                        ])),
                  ),
                  gapH18,
                  Container(
                    // margin: EdgeInsets.only(left: 174.w),
                    margin: EdgeInsets.only(left: 24.w),
                    padding: EdgeInsets.only(left: 30.w),
                    child: RichText(
                        text: TextSpan(
                            text: "${MultiLanguage.serviceCharge.tr}: ",
                            style: TextStyles.textSixthColor28,
                            children: [
                          TextSpan(
                              text: '¥ ${goodsChildEntity.serviceCost ?? ''}',
                              style: TextStyles.textNormal28)
                        ])),
                  ),
                  gapH18,
                ],
              ),
            ),
            Visibility(
              visible: goodsChildEntity.totalCount != null,
              child: GestureDetector(
                onTap: () {
                  goodsChildEntity.isExpand = !goodsChildEntity.isExpand;
                  baseGetxController!.update();
                },
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Container(
                      color: ThemeUtil.getTheme().dividingLineColor(),
                      width: double.infinity,
                      height: 0.7,
                    ),
                    Container(
                      color: Colors.transparent,
                      width: double.infinity,
                      padding: EdgeInsets.symmetric(vertical: 16.w),
                      height: 60.w,
                      child: LocalImage(
                        goodsChildEntity.isExpand ? 'admin_expand_close' : 'admin_expand_open',
                        width: 30.w,
                        height: 30.w,
                        package: Constant.packAdmin(),
                      ),
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
    return widget;
  }

  _showAddGoodsInfoDialog(int index,GoodsChildEntity goodsChildEntity) {
    var temporaryGoodsChildEntity = $GoodsChildEntityFromJson($GoodsChildEntityToJson(goodsChildEntity));
    Map<String, dynamic> arguments = {};
    arguments['Goods'] = temporaryGoodsChildEntity;
    arguments['OriginalGoods'] = goodsChildEntity;
    arguments['index'] = index;
    arguments['CallBack'] = _determine;
    DialogUtil.showAddGoodsInfoDialog(arguments: arguments);
  }

  _determine(GoodsChildEntity originalGoodsChildEntity, GoodsChildEntity temporaryGoodsChildEntity,int index) {
    baseGetxController!.listDataSelected.value[index] = temporaryGoodsChildEntity;
    baseGetxController!.updateCount();
    baseGetxController!.update();
  }
}
